package com.youme.api;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

/**
 * Time:3/21/21 7:17 PM
 * Author:
 * Description:
 */
public class CommandAdapter<T> implements JsonDeserializer<T> {

    @Override
    public T deserialize(
        JsonElement json, Type typeOfT,
        JsonDeserializationContext context)
        throws JsonParseException {
        if (json.isJsonObject()) {//判断类型正确，则按默认的返回
            return context.deserialize(json, new TypeToken<T>() {
            }.getType());
        }
        return null;
    }
}
